<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script src="https://unpkg.com/vue@next"></script>

    <div id="app">

    </div>

    <script>
        const myMixin = {
            data(){
                return {
                    name: 'kenny.bai',
                    age: 18,
                    score: 100
                }
            },
            methods: {
                foo() {
                    console.log('foo');
                },
                conflicting() {
                    console.log('from mixin');
                }
            }
        }

        const myMixin1 = {
            methods: {
                foo(){
                    console.log('mixin1 foo')
                },
                conflicting(){
                    console.log('conflicting myMixin1');
                }
            }
        }

        const app = Vue.createApp({
            // 多个混入模块，如果出现同名方法，后混入的同名方法会优先生效
            mixins:[myMixin, myMixin1],
            data(){
                // 如果混入的属性与组件自身有冲突，会以组件自身的属性优先
                return {
                    name: 'nancy',
                    age: 19
                }
            },
            methods: {
                bar(){
                    console.log('bar');
                },
                conflicting(){
                    // 组件自身的同名方法会优先生效
                    console.log('from self');
                }
            },
            created(){
                console.log('data:', this.$data)
            }
        })

        const vm = app.mount('#app');

        vm.foo();
        vm.bar();
        vm.conflicting();
    </script>
</body>
</html>